package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.CustomerReturnList;
import com.atguigu.jxc.entity.CustomerReturnListGoods;
import com.atguigu.jxc.entity.saleListGoodsCount;
import com.atguigu.jxc.service.CustomerReturnListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: CustomerReturnListGoodsController
 * Description:
 * Date: 2022/1/17 23:58
 *
 * @version:
 * @since JDK 1.8
 */
@RestController
@RequestMapping("/customerReturnListGoods")
public class CustomerReturnListGoodsController {

    @Autowired
    private CustomerReturnListGoodsService customerReturnListGoodsService;

    @PostMapping("/save")
    public ServiceVO saveCustomerReturnListGoods(CustomerReturnList customerReturnList, String customerReturnListGoodsStr ,HttpSession session){

        try {
            customerReturnListGoodsService.saveCustomerReturnListGoods(customerReturnList,customerReturnListGoodsStr, session);
            return new ServiceVO<>(100,"请求成功");

        }catch (Exception e){
            e.printStackTrace();
        }

        return new ServiceVO<>(101,"添加或修改失败");
    }


    @PostMapping("/list")
    public Map<String,Object> getCustomerReturnListGoods(String returnNumber, Integer customerId, Integer state, String sTime,String eTime){
        List<CustomerReturnList> customerReturnListList = customerReturnListGoodsService.getCustomerReturnListGoods(returnNumber,customerId,state,sTime,eTime);


        HashMap<String, Object> stringObjectHashMap = new HashMap<>();

        stringObjectHashMap.put("rows",customerReturnListList);
        return stringObjectHashMap;
    }


    @PostMapping("/goodsList")
    public Map<String,Object> getGoodsList(Integer customerReturnListId){
        List<CustomerReturnListGoods> customerReturnListGoodsList = customerReturnListGoodsService.getGoodsList(customerReturnListId);


        HashMap<String, Object> stringObjectHashMap = new HashMap<>();

        stringObjectHashMap.put("rows",customerReturnListGoodsList);
        return stringObjectHashMap;
    }

    @PostMapping("/delete")
    public ServiceVO deleteCustomerReturnListGoods(Integer customerReturnListId){
        try {
            customerReturnListGoodsService.deleteCustomerReturnListGoods(customerReturnListId);
            return new ServiceVO<>(100,"请求成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return new ServiceVO<>(101,"删除失败");

    }


    @PostMapping("/count")
    public List<saleListGoodsCount> count(String sTime, String eTime , Integer goodsTypeId, String codeOrName){



        List<saleListGoodsCount> saleListGoodsCountList = customerReturnListGoodsService.count(sTime, eTime ,goodsTypeId, codeOrName);


        return saleListGoodsCountList;




    }
}
